package com.me.darkness_is_coming.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.utils.viewport.StretchViewport;
import com.me.darkness_is_coming.actors.MenuButton;
import com.me.darkness_is_coming.main.MainGame;

public class PauseScreen implements Screen
{
    private Texture background_image;
    private SpriteBatch batch;
    private Stage stage;
    private MenuButton resumeButton;
    private MenuButton homeButton;

    public PauseScreen(SpriteBatch batch)
    {
        this.batch = batch;
        background_image = new Texture("data/Fons/PauseFon.png");
        resumeButton = new MenuButton(new Texture("data/Menu/MenuButtonResume.png"), MenuButton.PLAY, Gdx.graphics.getWidth()*0.238f, Gdx.graphics.getHeight()*0.609f, Gdx.graphics.getWidth()*0.523f, Gdx.graphics.getWidth()*0.083f);
        homeButton = new MenuButton(new Texture("data/Menu/MenuButtonHome.png"), MenuButton.HOME, Gdx.graphics.getWidth()*0.238f, Gdx.graphics.getHeight()*0.515f, Gdx.graphics.getWidth()*0.523f, Gdx.graphics.getWidth()*0.083f);
        resumeButton.clearListeners();
        resumeButton.addListener(new InputListener()
        {
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
            {
                MainGame.getInstance().resumeGame();
                return false;
            }

            public void touchUp (InputEvent event, float x, float y, int pointer, int button)
            {
            }
        });

        stage = new Stage(new StretchViewport(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()));
        stage.addActor(resumeButton);
        stage.addActor(homeButton);
    }

    @Override
    public void render(float delta)
    {
        Gdx.gl.glClearColor(27f/255f, 196f/255f, 245f/255f, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        batch.begin();
        batch.draw(background_image, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        batch.end();
        stage.act(delta);
        stage.draw();
    }

    @Override
    public void resize(int width, int height)
    {
        stage.getViewport().update(width, height, false);
    }
    @Override
    public void show()
    {
        Gdx.input.setInputProcessor(stage);
    }
    @Override
    public void hide()
    {
        //
    }
    @Override
    public void pause()
    {
        //
    }
    @Override
    public void resume()
    {
        //
    }
    @Override
    public void dispose()
    {
        stage.dispose();
        background_image.dispose();
        resumeButton.dispose();
        homeButton.dispose();
    }
}
